
***************************************************************************************************************
/*
THIS DO-FILE:
Gets cohort-level input profiles (biennial for main model and annual for robustness check)
*/
***************************************************************************************************************


use "my_sample_long.dta", clear
merge 1:1 hhidpn wave using "imputed_kid_assets.dta", nogen

keep hhidpn wave assets careneed avinc412 keducbin kassets cohort age ltci
keep if cohort<=5

reshape wide assets careneed kassets keducbin age ltci, i(hhidpn) j(wave)

*top/bottom code negative and huge assets: 
replace assets4=0 if assets4<0 
replace assets4=1000000 if assets4>1000000 & assets4!=.
replace kassets4=0 if kassets4<0 
replace kassets4=1000000 if kassets4>1000000 & kassets4!=.

gen kidhieduc=(inlist(keducbin4,3)) if inlist(keducbin4,1,2,3)
replace kidhieduc=0 if kidhieduc==. //set to HS if missing

*put age in model numbers (model starts at 1, and each period is two years)
gen 	agemodel4=1 if cohort==1 //65 
replace agemodel4=4	if cohort==2 //71
replace agemodel4=6 if cohort==3 //75
replace agemodel4=9 if cohort==4 //81
replace agemodel4=11 if cohort==5 //85

xtile PI3=avinc412, nq(3)
	
sum kassets4, det
replace kassets4=r(p50) if kassets4==. //give kid median assets if missing (just a few of them)

replace ltci4=0 if mi(ltci4) //seems like most are nos given responses in later waves
gen float ltci=ltci4

preserve
keep cohort agemodel4 assets4 PI3 ltci kidhieduc kassets4 careneed4 careneed5 careneed6 careneed7 careneed8 careneed9 careneed10 careneed11 careneed12
order cohort agemodel4 assets4 PI3 ltci kidhieduc kassets4 careneed4 careneed5 careneed6 careneed7 careneed8 careneed9 careneed10 careneed11 careneed12
corr assets4 kassets4
outsheet using "input_profiles_cohort.out", nonames replace
restore

*do yearly input profiles now (same careneed as previous year on off years)
keep hhidpn cohort agemodel4 assets4 PI3 ltci kidhieduc kassets4 careneed4 careneed5 careneed6 careneed7 careneed8 careneed9 careneed10 careneed11 careneed12
order hhidpn cohort agemodel4 assets4 PI3 ltci kidhieduc kassets4 careneed4 careneed5 careneed6 careneed7 careneed8 careneed9 careneed10 careneed11 careneed12
reshape long careneed, i(hhidpn) j(wave)
expand 2, generate(duplicated)
gen waveannual=(wave-4)*2+4
replace waveannual=waveannual+1 if duplicated==1
drop duplicated wave
reshape wide careneed, i(hhidpn) j(waveannual)
drop hhidpn
order cohort agemodel4 assets4 PI3 ltci kidhieduc kassets4 careneed4 careneed5 careneed6 careneed7 careneed8 careneed9 careneed10 ///
	  careneed11 careneed12 careneed13 careneed14 careneed15 careneed16 careneed17 careneed18 careneed19 careneed20 careneed21
outsheet using "input_profiles_cohortannual.out", nonames replace


******************************************************************************************
